<template>
  <div class="notice-bar">
    <el-icon class="ChatLineRound">
      <ChatDotSquare />
    </el-icon>
    <el-icon class="rightIco">
      <DArrowRight />
    </el-icon>
    <u-notice-bar vertical background="#fff" :data="noticeList"> </u-notice-bar>
  </div>
</template>
<script lang="ts" setup>
import { ref, inject } from 'vue'
import { getTalkHttp } from '@/utils/http/talkHttp'

import { ChatDotSquare, DArrowRight } from '@element-plus/icons-vue'
type noticeItem = {
  talk: string
}
const store: any = inject('store')
const noticeList = ref<string[]>([])
function getNoticeList() {
  if (store.state.talkList.length) {
    noticeList.value = (store.state.talkList as any[])
      .slice(0, 5)
      .map((item) => item.talk)
  } else {
    getTalkHttp(1).then((res) => {
      noticeList.value = (res.data.info.data as noticeItem[]).map(
        (item) => item.talk
      )
      store.postTalk(res.data.info.data, res.data.info.num)
    })
  }
}
getNoticeList()
</script>
<style lang="scss" scoped>
.notice-bar {
  position: relative;
  width: 100%;
  cursor: pointer;

  .ChatLineRound {
    position: absolute;
    font-size: 20px;
    left: 20px;
    top: 10px;
    color: #888;
  }

  .rightIco {
    position: absolute;
    top: 14px;
    right: 10px;
    animation: move 2s infinite;
    color: #888;
  }

  :deep(.el-carousel__item) {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 100%;
    color: #888;
    line-height: 44px;
    text-align: center;
  }
}

@keyframes move {
  0% {
  }

  100% {
    opacity: 0;
    transform: translateX(70%);
  }
}

@media (max-width: 760px) {
  .notice-bar {
    .ChatLineRound {
      left: 10px;
    }
  }
}
</style>
